﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Prodma.Panel.Helper
{
    public class ImageResizer
    {
        public static void CreateThumbnailImage(string source, string destination, int widht, int height)
        {
            Image image = Image.FromFile(source);
            int srcWidth = image.Width;
            int srcHeight = image.Height;

            Decimal sizeRatio = ((Decimal)srcHeight / srcWidth);
            int thumbHeight = Decimal.ToInt32(sizeRatio * widht);

            Bitmap bmp = new Bitmap(widht, height);

            Graphics gr = Graphics.FromImage(bmp);
            gr.SmoothingMode = SmoothingMode.HighQuality;
            gr.CompositingQuality = CompositingQuality.HighQuality;
            gr.InterpolationMode = InterpolationMode.High;            

            Rectangle rectDestination = new Rectangle(0, 0, widht, height);
            gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);
            bmp.Save(destination);

            bmp.Dispose();
            image.Dispose();
        }       
    }
}
